﻿using System.ComponentModel;
using System.Windows;

namespace DemoApplication
{
    /// <summary>
    /// Interaction logic for LoadingWindow.xaml
    /// </summary>
    public partial class LoadingWindow : Window
    {
        private BackgroundWorker m_LoadingWorker;

        public LoadingWindow()
        {
            InitializeComponent();
        }

        #region event handling functions

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            m_LoadingWorker = new BackgroundWorker();
            m_LoadingWorker.DoWork += LoadingWorker_DoWork;
            m_LoadingWorker.RunWorkerCompleted += LoadingWorker_RunWorkerCompleted;
            m_LoadingWorker.RunWorkerAsync();
        }

        void LoadingWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            MainWindow mainWindow = new MainWindow();
            mainWindow.Show();
            this.Close();
        }

        private void LoadingWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // Hack, do this to prevent app hangs a small time at the first query
            DataCommunicator.GetMaterialService().GetAll();
        }

        #endregion
    }
}
